using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
 

public partial class jobsaved : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        if (!IsPostBack)
            ShowData();

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;       
        ShowData();
    }
    void ShowData()
    {
        try
        {
            ControlHelper cls = new ControlHelper("");
            cls.CommandText = "SPViewSavedJob";
            cls.ParameterCollection = new string[1] { "@UserID" };
            cls.ValueCollection = new string[1] { 
            Convert.ToString(Session.Contents["jsuserid"])};
            cls.CommandType = CommandType.StoredProcedure;
            cls.InitProperties();
            cls.FillDataTableToGridView(this.GridView1, 10, 10, PagerButtons.NumericFirstLast);
            if(GridView1.Rows.Count>1)
                btnDelete.Enabled = true;
            else
                btnDelete.Enabled = false;
        }
        catch (Exception ex)
        {
            Literal1.Text = ex.Message;
        }
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        string jobID ="";
        foreach(GridViewRow gridViewRow in GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)
            gridViewRow.FindControl("chkJobID");
            if(checkBox.Checked)
            {
                try
                {
                    jobID += 
                    gridViewRow.Cells[1].Text +",";
                }
                catch (Exception ex)
                {
                    Literal1.Text = ex.Message;
                }
            }
            
        }
        if(jobID != "")
        {
            jobID = jobID.Substring(0,jobID.Length-1);
            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider();
            foreach (string job in jobID.Split(','))
                sqlServerProvider.DeleteSavedJob(
                Convert.ToString(Session["jsuserid"]), job);
            
            ShowData();
        }
    }
}
